<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/jquery-ui-1.10.3.custom.min.css">
    <link rel="stylesheet" type="text/css" href="css/ui.jqgrid.css">
    <link rel="stylesheet" type="text/css" href="css/mycss.css">
    <style>
.ui-icon-plus {
	background-position: -16px -128px;
}
</style>
    <script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="js/grid.locale-he.js" type="text/javascript"></script>
    <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        //style="vertical-align:top"

        $(document).ready(function () {
			
			
			 $("#list").jqGrid({
             url:"gridFunctions/personActions.php",
			 editurl: "gridFunctions/personActions.php",
			 direction: 'rtl',
			 async: false,
			 datatype: 'json',
     		 pager: '#pager',
			// colNames: ['שורה','פעולות','מספר לקוח','ת"ז', 'שם פרטי', 'שם משפחה','מייל', 'עיר', 'רחוב ובית', 'טלפון', 'פקס', 'פלאפון'],
             colNames: ['מספר לקוח','ת"ז', 'שם פרטי', 'שם משפחה','מייל', 'עיר', 'רחוב ובית', 'טלפון', 'פקס', 'פלאפון'],
             colModel: [
		//	{name:'rowNumber',index:'rowNumber', width:20,sortable:false,search : false},
			//{name:'act',index:'act', width:75,sortable:false,search : false},
			 { name: 'person_number', index: 'person_number', width: 60, align: 'left',  editable: false ,align:'right' },
            { name: 'person_id', index: 'person_id', width: 60, align: 'left', editable: true,align:'right',editrules:{required:true,integer:true} },
            { name: 'firstname', index: 'firstname', width: 120, align: 'left', editable: true,align:'right' },
		    { name: 'lastname', index: 'lastname', width: 120, align: 'left', editable: true,align:'right' },
			{ name: 'email', index: 'email', width: 120, align: 'left', editable: true,align:'right',editrules:{required:true,email:true} },
            { name: 'city', index: 'city', width: 70, align: 'left', editable: true,align:'right' },
            { name: 'address', index: 'address', width: 70, align: 'left', editable: true,align:'right' },
            { name: 'telephone', index: 'telephone', width: 80, align: 'left', editable: true,align:'right' },
            { name: 'fax', index: 'fax', width: 60, align: 'left', editable: true,align:'right' },
            { name: 'cellphone', index: 'cellphone', width: 180, align: 'left', editable: true,align:'right'}],
            pager: jQuery('#pager'),
            rowNum: 20,
            rowList: [5, 10, 20, 50],
            sortname: 'person_number',
            sortorder: "desc",
			
		
          /*  gridComplete: function()
				{
					//jQuery("#grid_id").editRow(rowid, keys, oneditfunc, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);
					//jQuery("#grid_id").saveRow(rowid, successfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);
				------	editparameters = {
					"keys" : false,
					"oneditfunc" : null,
					"successfunc" : null,
					"url" : null,
					"extraparam" : {},
					"aftersavefunc" : null,
					"errorfunc": null,
					"afterrestorefunc" : null,
					"restoreAfterError" : true,
					"mtype" : "POST"
					}
					
					saveparameters = {
					"successfunc" : null,
					"url" : null,
					"extraparam" : {},
					"aftersavefunc" : null,
					"errorfunc": null,
					"afterrestorefunc" : null,
					"restoreAfterError" : true,
					"mtype" : "POST"
					}
					
				var ids = jQuery("#list").jqGrid('getDataIDs');
				
				for(var i=0;i < ids.length;i++){
				var cl = ids[i];
				be ="<img class='imgBTN' src='css/25EDIT.png' alt='ערוך' height='25' width='25' onclick=\"$('#list').jqGrid('editRow',$('.ui-state-hover').attr('id'),  editparameters);\"  />"
				se ="<img class='imgBTN' src='css/25SAVE.png' alt='שמור' height='25' width='25' onclick=\"$('#list').jqGrid('saveRow',$('.ui-state-hover').attr('id'),  saveparameters);\"  />"
				ce ="<img class='imgBTN' src='css/25CANCEL.png' alt='בטל' height='25' width='25' onclick=\"$('#list').restoreRow($('.ui-state-hover').attr('id'));\"  />"
				jQuery("#list").jqGrid('setRowData',ids[i],{act:be+se+ce});
				jQuery("#list").jqGrid('setRowData',ids[i],{rowNumber:i});
				}	
	}, // -- end of     gridComplete: function()-----*/
            mtype: "POST",
		//loadonce: true,
			postData:{oper:'view'},
            viewrecords: true,
            imgpath: '../../Scripts/css/Aristo/images',
            autowidth: true,
            height: "100%"
            }); // -- end of   $("#list").jqGrid({
			

 $("#list").jqGrid('navGrid', '#pager', {edit:true,add:true,del:true,refresh:true, closeAfterAdd: true,reloadAfterSubmit:true, search:false},
      // Edit dialog parameters
      {
		reloadAfterSubmit: true,
        closeAfterEdit: true,
		//editData: {person_number: function() {  return "7"; } },
		onclickSubmit: function (rp_ge, postdata) 
		{
			return { person_number: getSelectedCell('person_number') };
		},
		afterSubmit: function(response,postdata)
		{ 
			if(response.responseText=="ok")
			{
			success=true;
			alert("פרטי הלקוח התעדכנו בהצלחה")
			}
			else 
			{
				
			success = false;
			alert("פרטי הלקוח לא התעדכנו בהצלחה")
			}
			return [success,response.responseText] 
        }
      },
      // Add dialog parameters
      {
		reloadAfterSubmit: true,
        closeAfterAdd: true,
		afterSubmit: function(response,postdata){ 
			if(response.responseText=="ok")
			{
			success=true;
			alert("לקוח התווסף בהצלחה")
			}
			else 
			{
			success = false;
			alert("לקוח לא התווסף בהצלחה")
			}
			return [success,response.responseText] 
        }
		
      },
      // Delete dialog parameters
      {
	  reloadAfterSubmit: true,
	  onclickSubmit: function (rp_ge, postdata) 
		{
			return { person_number: getSelectedCell('person_number') };
		},
		afterSubmit: function(response,postdata){ 
			if(response.responseText=="ok")
			{
			success=true;
			alert("לקוח נמחק בהצלחה")
			}
			else 
			{
			success = false;
			alert("לקוח לא נמחק בהצלחה")
			}
			return [success,response.responseText] 
        }
	
	  },
      // Search dialog parameters
      {},
      // View dialog parameters
      {}
);
 $('#list').jqGrid('filterToolbar', { searchOnEnter: true, enableClear: false });



	
  });// -- end of  $(document).ready(function ()
function getSelectedCell(str)
{
var grid = jQuery('#list');
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id,str);
return myCellData;
}
        

               
    </script>
    <title>ניהול לקוחות</title>
    </head>

    <body  dir="rtl">
<h1>רשימת לקוחות </h1>
<div id="lc">
      <table id="list" class="scroll" cellpadding="0" cellspacing="0">
  </table>
      <div id="pager" class="scroll" style="text-align: center;"> </div>
    </div>
</body>
</html>